﻿using Mes.Application.DTO.Inputs.Operations;
using Mes.Application.DTO.Inputs.WorkOrders;

namespace Mes.Application.DTO.Results.WorkOrders
{
    public class JobResult
    {
        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;

        /// <summary>
        /// 操作名称
        /// </summary>
        public string? Job_Desc { get; set; }

        /// <summary>
        /// 所需完工日期/时间
        /// </summary>
        public DateTime? Req_Finish_Time_Local { get; set; }

        /// <summary>
        /// 优先级
        /// </summary>
        public int Job_Priority { get; set; }

        /// <summary>
        /// 运行位置Id
        /// </summary>
        public int? Run_Ent_Id { get; set; }

        /// <summary>
        /// 运行位置名称
        /// </summary>
        public string? Run_Ent_Name { get; set; }

        /// <summary>
        /// 产量
        /// </summary>
        public double Qty_Prod { get; set; }

        /// <summary>
        /// 次品数
        /// </summary>
        public double Qty_Rejected { get; set; }

        /// <summary>
        /// 物料Id
        /// </summary>
        public int Item_Id { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string Item_Name { get; set; } = string.Empty;

        /// <summary>
        /// 状态
        /// </summary>
        public int State_Cd { get; set; }

        /// <summary>
        /// 状态名称
        /// </summary>
        public string State_Desc { get; set; } = string.Empty;

        /// <summary>
        /// 开工数量
        /// </summary>
        public float Qty_At_Start { get; set; }

        /// <summary>
        /// 所需产量
        /// </summary>
        public float Qty_Reqd { get; set; }

        /// <summary>
        /// 可调度地Id
        /// </summary>
        public int Init_Sched_Ent_Id { get; set; }

        /// <summary>
        /// 可调度地名称
        /// </summary>
        public string Init_Sched_Ent_Name { get; set; } = string.Empty;

        /// <summary>
        /// 调度地Id
        /// </summary>
        public int Target_Sched_Ent_Id { get; set; }

        /// <summary>
        /// 调度地名称
        /// </summary>
        public string Target_Sched_Ent_Name { get; set; } = string.Empty;

        /// <summary>
        /// 实际开工日期/时间
        /// </summary>
        public DateTime? Act_Start_Time_Local { get; set; }

        /// <summary>
        /// 实际完工日期/时间
        /// </summary>
        public DateTime? Act_Finish_Time_Local { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Notes { get; set; }
    }

    public class GettingJobQueueResult
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Wo_Id { get; set; } = string.Empty;

        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;

        /// <summary>
        /// 可调度地Id
        /// </summary>
        public int Init_Sched_Ent_Id { get; set; }

        /// <summary>
        /// 可调度地名称
        /// </summary>
        public string Init_Sched_Ent_Name { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public int State_Cd { get; set; }

        /// <summary>
        /// 状态名称
        /// </summary>
        public string State_Desc { get; set; }

        /// <summary>
        /// 所需完工日期/时间
        /// </summary>
        public DateTime? Req_Finish_Time_Local { get; set; }

        /// <summary>
        /// 优先级
        /// </summary>
        public int Job_Priority { get; set; } = 1;


        /// <summary>
        /// 工艺ID
        /// </summary>
        public string? Process_Id { get; set; } = string.Empty;

        /// <summary>
        /// 物料ID
        /// </summary>
        public int MaterialId { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string MaterialName { get; set; }

        /// <summary>
        /// 开工数量
        /// </summary>
        public double Qty_At_Start { get; set; }

        /// <summary>
        /// 所需产量
        /// </summary>
        public double Qty_Reqd { get; set; }

        /// <summary>
        /// 显示顺序
        /// </summary>
        public int Display_Seq { get; set; }
    }

    /// <summary>
    /// 作业详情
    /// </summary>
    public class JobDetailsResult : JobResult
    {
        /// <summary>
        /// BOM
        /// </summary>
        public List<JobBOMResult> JobBOMs { get; set; } = new List<JobBOMResult>();

        /// <summary>
        /// 工步组列表
        /// </summary>
        public List<JobStepGrpResult> JobStepGrps { get; set; } = new List<JobStepGrpResult>();
    }

    /// <summary>
    /// 作业下BOM详情
    /// </summary>
    public class JobBOMResult : JobBOMCommon
    {
        public JobBOMResult() { }

        public JobBOMResult(int materialId, string materialCode, string materialName, int? defaultStorageEntity, double quantity, /*double? maxConsumeQuantity, double? minConsumeQuantity,*/ double startReqQuantity, int bomPos)
        {
            MaterialId = materialId;
            MaterialCode = materialCode;
            MaterialName = materialName;
            DefaultStorageEntity = defaultStorageEntity;
            Quantity = quantity;
            // MaxConsumeQuantity = maxConsumeQuantity;
            // MinConsumeQuantity = minConsumeQuantity;
            StartReqQuantity = startReqQuantity;
            Bom_Pos = bomPos;
        }

        public JobBOMResult(int materialId, string materialCode, string materialName, int? defaultStorageEntity, string? defaultStorageEntityCode, string? defaultStorageEntityName, double quantity, /*double? maxConsumeQuantity, double? minConsumeQuantity,*/ double startReqQuantity, int bomPos)
        {
            MaterialId = materialId;
            MaterialCode = materialCode;
            MaterialName = materialName;
            DefaultStorageEntity = defaultStorageEntity;
            DefaultStorageEntityCode = defaultStorageEntityCode;
            DefaultStorageEntityName = defaultStorageEntityName;
            Quantity = quantity;
            // MaxConsumeQuantity = maxConsumeQuantity;
            // MinConsumeQuantity = minConsumeQuantity;
            StartReqQuantity = startReqQuantity;
            Bom_Pos = bomPos;
        }

        /// <summary>
        /// 物料编码
        /// </summary>
        public string MaterialCode { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string MaterialName { get; set; }

        /// <summary>
        /// 默认生产单元编码
        /// </summary>
        public string? DefaultStorageEntityCode { get; set; }

        /// <summary>
        /// 默认生产单元名称
        /// </summary>
        public string? DefaultStorageEntityName { get; set; }

        /// <summary>
        /// 位置
        /// </summary>
        public int Bom_Pos { get; set; }
    }

    /// <summary>
    /// 作业下的工步组
    /// </summary>
    public class JobStepGrpResult : JobStepGrpCommon
    {
        /// <summary>
        /// 工步列表
        /// </summary>
        public IList<JobStepResult> JobSteps { get; set; } = new List<JobStepResult>();
    }

    /// <summary>
    /// 工步出参
    /// </summary>
    public class JobStepResult
    {
        /// <summary>
        /// 工步编号
        /// </summary>
        public int Step_No { get; set; }

        /// <summary>
        /// 工步顺序
        /// </summary>
        public int Step_Seq { get; set; }

        /// <summary>
        /// 工步名称
        /// </summary>
        public string? Step_Name { get; set; } = null;

        /// <summary>
        /// 工步描述
        /// </summary>
        public string Step_Desc { get; set; } = string.Empty;

        /// <summary>
        /// 工步BOM列表
        /// </summary>
        public IList<JobBomStepResult> JobBomSteps { get; set; } = new List<JobBomStepResult>();
    }

    public class JobBomStepResult
    {
        public JobBomStepResult(string materialCode, string materialName, double quantity, double qty_Per_Parent_Item, double remainingQty)
        {
            MaterialCode = materialCode;
            MaterialName = materialName;
            Quantity = quantity;
            Qty_Per_Parent_Item = qty_Per_Parent_Item;
            RemainingQty = remainingQty;
        }
        /// <summary>
        /// 物料编码
        /// </summary>
        public string MaterialCode { get; set; }
        /// <summary>
        /// 物料名称
        /// </summary>
        public string MaterialName { get; set; } = string.Empty;

        /// <summary>
        /// 数量
        /// </summary>
        public double Quantity { get; set; }

        /// <summary>
        /// 工步数量
        /// </summary>
        public double Qty_Per_Parent_Item { get; set; }

        /// <summary>
        /// 剩余数量
        /// </summary>
        public double RemainingQty { get; set; }

    }
}
